package org.example.controller.SpringBoot300;

import org.example.util.file.FileUtil;
import org.example.util.log.Logac;
import org.example.util.log.text.StringToolUtil;
import org.example.util.log.text.WordUtil;

import java.io.File;
import java.util.List;

/**
 * @auther admin闫
 * @Descriptopn 截取论文中的摘要部分（为做音频做准备）
 * @date 2024/4/7 19:43
 */
public class SpringBoot300LWTQ {
    public static void main(String[] args) {
        /*
        1.拿到所有论文的URL
        2.读取这写论文的文本，并截取
        3.创建这个文本的路径并写入文本
        */
        List<String> allFilePaths = FileUtil.getAllDGFiles("H:\\短视频工作目录\\mudidir");
        int i=0;

        for (String allFilePath : allFilePaths) {
            String fileName = FileUtil.getFileName(allFilePath);
            if (fileName.contains("论文")){
                if (FileUtil.getFileType(allFilePath).equals("doc")){
                    i++;
                    try {
                        String s = WordUtil.searchWordDoc(allFilePath);
                        String s1 = StringToolUtil.spiltA_B("要", "关键", s);
                        if (s1.length()>900){
                            String s2 = StringToolUtil.spiltA_("要",s1);
                            if (s2.length()>900){
                                String s3 = StringToolUtil.spiltA_("要",s2);
                                write(allFilePath,s3);
                            }else {
                                write(allFilePath,s2);
                            }
                        }else {
                            write(allFilePath,s1);
                        }
                    }catch (Exception e){
                        Logac.log(allFilePath+"     手工处理");
                    }
                }
            }
        }


        int y=0;
        for (String allFilePath : allFilePaths) {
            String fileName = FileUtil.getFileName(allFilePath);
            if (fileName.contains("论文")){
                if (FileUtil.getFileType(allFilePath).equals("docx")){
                    y++;
                    try {
                    String s = WordUtil.searchWordDocX(allFilePath);
                    String s1 = StringToolUtil.spiltA_B("要", "关键", s);
                        if (s1.length()>900){
                            String s2 = StringToolUtil.spiltA_("要",s1);
                            if (s2.length()>900){
                                String s3 = StringToolUtil.spiltA_("要",s2);
                                write(allFilePath,s3);
                            }else {
                                write(allFilePath,s2);
                            }
                        }else {
                            write(allFilePath,s1);
                        }
                    }catch (Exception e){
                        Logac.log(allFilePath+"     手工处理");
                    }
                }
            }
        }


    }

    public static void write(String path,String text){
        String s = FileUtil.shangjFileName(path);
        // 创建File对象
        File file = new File(path);
        // 获取文件的父目录
        File parentDir = file.getParentFile();
        System.out.println(parentDir.toString());
        FileUtil.createAndWriteToFile(parentDir.toString()+"\\"+s+".txt",text);//写入原来的文件目录
        //写入指定
        FileUtil.createAndWriteToFile("H:\\毕业设计工作目录\\batch_processing\\batch_processing\\txt"+"\\"+s+".txt",text);
    }


}
